﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.Mvc;

namespace DBMS.Models.Query 
{
    public static class FieldDefinitions 
    {
       // private static List<SelectListItem> _attachWith;
        private static IEnumerable<SelectListItem> _fieldNames;
        private static List<SelectListItem> _operatorDateTime;
        private static List<SelectListItem> _operatorNumber;
        private static List<SelectListItem> _operatorText;

        private static Dictionary<string, FieldDefinition> _fields;

        static FieldDefinitions() 
        {
            //_attachWith = new List<SelectListItem>();
            //_attachWith.Add(new SelectListItem { Text = "And", Value = "And" });
            //_attachWith.Add(new SelectListItem { Text = "Or", Value = "Or" });

            _operatorDateTime = new List<SelectListItem>();
            _operatorDateTime.Add(new SelectListItem { Text = "After", Value = "after" });
            _operatorDateTime.Add(new SelectListItem { Text = "Before", Value = "before" });
            _operatorDateTime.Add(new SelectListItem { Text = "On", Value = "on" });

            _operatorNumber = new List<SelectListItem>();
            _operatorNumber.Add(new SelectListItem { Text = "Less Than", Value = "less" });
            _operatorNumber.Add(new SelectListItem { Text = "Greater Than", Value = "greater" });

            _operatorText = new List<SelectListItem>();
            _operatorText.Add(new SelectListItem { Text = "Equals", Value = "equals" });
            _operatorText.Add(new SelectListItem { Text = "Not Equals", Value = "notEquals" });

            _fields = new Dictionary<string, FieldDefinition>();
            _fields["First Name"] = new FieldDefinition { Name = "First Name", Operators = _operatorText, Type = Types.Text };
            _fields["Last Name"] = new FieldDefinition { Name = "Last Name", Operators = _operatorText, Type = Types.Text };
            _fields["SSN"] = new FieldDefinition { Name = "SSN", Operators = _operatorNumber, Type = Types.Number };
            _fields["Date of Birth"] = new FieldDefinition { Name = "Date of Birth", Operators = _operatorDateTime, Type = Types.DateTime };

            _fieldNames = from FieldDefinition field in _fields.Values
                          select new SelectListItem 
                          {
                              Text = field.Name,
                              Value = field.Name
                          };
        }

        //public static IEnumerable<SelectListItem> AttachWith 
        //{
        //    get 
        //    {
        //        return _attachWith;
        //    }
        //}

        public static IEnumerable<SelectListItem> FieldNames 
        {
            get 
            {
                return _fieldNames;
            }
        }

        public static IDictionary<string, FieldDefinition> Fields 
        {
            get 
            {
                return _fields;
            }
        }

    }
}
